/*
  ajax提交处理 底层
  parse method 提交方法
  parse url 提交的url
  parse data 提交的数据
  parse async 是否开启异步
  parse tan 是否弹出结果

   */
  function ajax(method,url,data,async=true,tan=true){
       var xhr;
         try{
           // Firefox, Opera 8.0+, Safari
            xhr = new XMLHttpRequest();
          }
         catch (e){
            // Internet Explorer
            xhr =new ActiveXObject("Msxml2.XMLHTTP");
          }
      if (method == 'formdata') {
        met = 'post';
      }else{
        met = method;
      }
      //如果不弹出 此变量存储结果
      rsu = '';
      xhr.open(met,url,async);
      if (method == 'post') {
        xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      }; 
      function collback(){
        if (xhr.status >= 200 && xhr.status < 300 || xhr.status == 304) {
          if (tan == true) {
            alert(xhr.responseText.trim());
          }else{
            rsu = xhr.responseText.trim();
          }  
        }else{
           alert('服务异常');
          }
      }
      xhr.onload = collback;
      xhr.send(data);
      if (tan == false) {
        return rsu;
      };
  }
   /* 
  格式化时间返回 注意t为毫秒数
  */
  function getdate(t){
    var time = new Date();
    time.setTime(t);
    return time.getFullYear()+'年'+(time.getMonth()+1)+'月'+time.getDate()+'日';
  }
  //取出文章
  function getart(){
    var url = '/index.php'+location.search+'&m=artall';

    var data = ajax('get',url,null,false,false);

    var data = eval(data);
    var inner = ''; 
    for (var i = 0; i < data.length; i++) {

         inner += '<tr><td>'+data[i]['art_id']+'</td>';
         inner += '<td>'+getdate(data[i]['pubtime']*1000)+'</td>';
         inner += '<td>'+data[i]['title']+'</td>';
         inner += '<td>'+data[i]['catname']+'</td>';
         inner += '<td><a href="/index.php?c=essay&tid='+data[i]['art_id']+'" target="_blank" >查看</a>&nbsp&nbsp&nbsp';
         inner += '<span onclick=dela('+data[i]['art_id']+')>删除</td></tr>';
    }; 
    return inner;
  }
